<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试Excel导入</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .container {
            background-color: #f5f5f5;
            padding: 20px;
            border-radius: 5px;
        }
        .form-group {
            margin-bottom: 15px;
        }
        .result {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            display: none;
        }
        .error {
            color: red;
            margin-top: 10px;
        }
        .success {
            color: green;
        }
        pre {
            background-color: #f8f8f8;
            padding: 10px;
            border-radius: 4px;
            overflow-x: auto;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>测试Excel图片导入</h1>

        <div class="form-group">
            <form id="uploadForm" enctype="multipart/form-data">
                <input type="file" name="file" accept=".xlsx,.xls" required>
                <button type="submit">上传并测试</button>
            </form>
        </div>

        <div id="result" class="result">
            <h3>处理结果：</h3>
            <pre id="resultContent"></pre>
        </div>

        <div id="error" class="error"></div>
    </div>

    <script>
        document.getElementById('uploadForm').addEventListener('submit', function(e) {
            e.preventDefault();

            const formData = new FormData(this);
            const resultDiv = document.getElementById('result');
            const resultContent = document.getElementById('resultContent');
            const errorDiv = document.getElementById('error');

            // 清除之前的结果
            resultDiv.style.display = 'none';
            errorDiv.textContent = '';

            fetch('', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                if (data.error) {
                    throw new Error(data.error);
                }

                // 格式化并显示结果
                resultContent.textContent = JSON.stringify(data, null, 2);
                resultDiv.style.display = 'block';
            })
            .catch(error => {
                errorDiv.textContent = error.message;
            });
        });
    </script>
</body>
</html>